#{extends 'main.html' /}
#{set roles2:''/}
*{userStories is availble}*
<h2><a style ="color:#400040;" href = "@{Projects.showProject((Long)project.getEntityId())}">${project.name}</a> > User Stories</h2>
<hr/>
<a href="@{ApplicationRoles.showAll(project.getEntityId())}">Application Roles</a>
<hr/>
#{secure.check 'Create/edit/Delete User story in my project'}
<a href="@{UserStories.index(project.getEntityId())}">+ Add User Story</a>
#{/secure.check}<br/><br/>
#{if userStories.isEmpty()}
	<label>
	    No user stories associated to that project
	</label>
#{/if}
#{else}
	#{list items:userStories, as:'user_stories'}
		<a class = "link" href="javascript:deleteStory('${user_stories.dependants.size()}','${user_stories.getEntityId()}','${user_stories.events.size()}','${user_stories.tasks.size()}','${user_stories.demos.size()}')" title="delete" style="color:red">x</a>
		#{list items:user_stories.appRoles, as:'roles'}
		#{set roles2:roles2+roles.name+", " /}
		#{/list}
		<a class = "link" title="edit" href="${user_stories.getEntityId()}"><img src="/public/images/edit-icon.png" border=0></a>&nbsp;&nbsp;&nbsp;As a/an #{get 'roles2' /} ${user_stories.story}
		<br/>
		#{set roles2:""/}
		<br>
	#{/list}
	<br/>
#{/else}
<script>
    function deleteStory(dependants, storyId, events, tasks, demos){
        if (dependants != 0) {
            showDialogHelper('Error!', 'This user story cannot be deleted because other stories are dependant on it.', false, '', 'error');
        }
        else {
            showDialogHelper('Confirmation', 'This user story is associated to ' + events + ' events, ' + tasks + ' tasks and ' + demos + ' demo entries. Are you sure you want to delete this story?', true, '/userstories/submitdeleteuserstory/' + storyId, 'prompt');
        }
    }
    
    $(function(){
        $(".link").tipTip();
    });
</script>
